function init() {

	fillTable();
}
var userCache = {};
var viewed = -1;
function fillTable() {//现实列表

	driver.findAll(function(userList) {
		dwr.util.removeAllRows("driverbody", {
			filter : function(tr) {
				return (tr.id != "pattern");
			}
		});
		var user, id;
		for ( var i = 0; i < userList.length; i++) {
			user = userList[i];
			id = user.id;
			dwr.util.cloneNode("pattern", {
				idSuffix : id
			});
			dwr.util.setValue("tidId" + id, user.idId);
			dwr.util.setValue("tidName" + id, user.idName);
			dwr.util.setValue("tidGender" + id, user.idGender);
			dwr.util.setValue("tidType" + id, user.idType);
			dwr.util.byId("pattern" + id).style.display = "";
			userCache[id] = user;
		}
	});
}
var currentId = null;
function editClicked(eleid) {//编辑
	// we were an id of the form "edit{id}", eg "edit42". We lookup the "42"
	currentId = eleid.substring(7);
	var user = userCache[currentId];
	dwr.util.setValues(user);
	lock();
}

function deleteClicked() {//删除
	if (currentId == null) {
		return;
	}

	// we were an id of the form "delete{id}", eg "delete42". We lookup the "42"
	var user = userCache[currentId];
	if (confirm("你确定要删除 " + user.idName + " 的用户 ?")) {
		dwr.engine.beginBatch();
		driver.del(user.id);
		fillTable();
		clear();
		dwr.engine.endBatch();
		currentId = null;
	}
}

function saveUser() {//添加user
	var user = {
		id : null,// 表的主键
		idId : null,// 司机编号
		idType : null,// 驾照类别
		idIdCard : null,// 身份证号
		idZip : null,// 邮政编号
		idDriverPhone : null,// 司机电话
		idDriverCellphone : null,// 司机手机
		idName : null,// 司机姓名
		idGender : null,// 性别
		idBirthday : null,// 出生日期
		idEducation : null,// 学历
		idDrivNum : null,// 驾照号码
		idState : null,// 收费状态
		idDriverAge : null,// 司机驾龄
		idCreditState : null,// 信誉情况
		idEmaile : null,// 电子邮箱
		idDriverAddress : null,// 司机地址
		idRun : null,// 经营路线
		idComment : null,// 备注
		idCooperationDate:null
	
	};
	dwr.util.getValues(user);
	if (user.idName == "") {
		return;
	}
	dwr.engine.beginBatch();

	if (user.id > 0) {
		driver.updata(user);
	} else {
		driver.save(user);
	}

	fillTable();
	dwr.engine.endBatch();
	inputSaveEdit();
	clear();
	currentId = null;
}

function search() {

}
